package com.bawei.product.controller;

import com.bawei.common.core.domain.R;
import com.bawei.product.domain.req.ProductInfoReq;
import com.bawei.product.domain.vo.ProductInfoVo;
import com.bawei.product.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.math3.stat.descriptive.summary.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("product")
@Api(tags = "商品管理")
@Validated
public class ProductController {

    @Autowired
    private ProductService productService;

    @PostMapping("/saveOrUpdate")
    @ApiOperation("添加")
    public R<Void> saveOrUpdate(@Valid @RequestBody ProductInfoReq productInfoReq){
        productService.saveOrUpdate(productInfoReq);
        return R.ok();
    }

    @GetMapping("/{productId}")
    @ApiOperation("根ID获取详情")
    public R<ProductInfoVo> getProductDetailById(@PathVariable("productId") @NotNull(message = "商品ID不能为空") Long productId){
        return R.ok(productService.getProductDetailById(productId));
    }
}
